package com.punch.user.controller;

import com.punch.common.dto.login.WXUserDTO;
import com.punch.common.model.LoginUser;
import com.punch.user.service.GuardianService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 监护人controller
 *
 * @author tanchangguo
 * @email 17607195327@163.com
 * @date 2020-07-21 19:10:02
 */
@RestController
@Api(tags = "监护人管理")
public class GuardianController {

    @Resource
    private GuardianService guardianService;

    /**
     * 根据openId获取监护人信息
     *
     * @param openId openId
     */
    @GetMapping(value = "/guardian/openid/{openId}")
    @ApiOperation(value = "根据openId获取监护人信息")
    public LoginUser getFeignGuardianByOpenId(@PathVariable String openId) {
        return guardianService.getFeignGuardianByOpenId(openId);
    }

    /**
     * 进行注册,不存在则注册,存在则返回
     *
     * @param wxUserDTO 微信用户表单
     */
    @PostMapping(value = "/guardian/openid/mobile")
    public void saveFeignGuardian(@RequestBody WXUserDTO wxUserDTO) {
        guardianService.saveFeignGuardian(wxUserDTO);
    }

}
